<template>
	<view class="goods-item">
		<view class="item-left">
			<radio color="#C00000" :checked='goodsInfo.goods_state' v-if="showRadio"  @click="radioChange"></radio>
			<image :src="goodsInfo.goods_small_logo || defaultPic" class="goods-pic"></image>
		</view>
		<view class="item-right">
			<view class="title">
				{{goodsInfo.goods_name}}
			</view>
			<view class="price">
				<text>{{goodsInfo.goods_price|price}}</text>
				<uni-number-box v-if="showNumber" :min="1" :max='999' :value='goodsInfo.goods_count' @change='numberChange' @blur='onblur'></uni-number-box>
			</view>
		</view>
	</view>
</template>

<script>
	import { mapMutations } from 'vuex'
	export default {
		name:"my-goods",
		props:{
			goodsInfo:{
				type:Object,
				default(){
					return {}
				}
			},
			showRadio:{
				type:Boolean,
				default:false
			},
			showNumber:{
				type:Boolean,
				default:false
			}
		},
		data() {
			return {
				defaultPic: 'https://img3.doubanio.com/f/movie/8dd0c794499fe925ae2ae89ee30cd225750457b4/pics/movie/celebrity-default-medium.png'
			};
		},
		filters:{
			price(val){
				return '￥'+ Number(val).toFixed(2)
			}
		},
		methods:{
			...mapMutations('cartModule', ['undataCartState','undataCartCount']),
			radioChange(){
				this.undataCartState({
					id:this.goodsInfo.goods_id,
					bool:!this.goodsInfo.goods_state
				})
			},
			numberChange(e){
				this.undataCartCount({
					id:this.goodsInfo.goods_id,
					val:e
				})
			},
			onblur(e){
				console.log('onblur',e);
				let val = +e.detail.value
				console.log(val);
				if(isNaN(val)){
					console.log('需要做点事情');
					this.undataCartCount({
						id:this.goodsInfo.goods_id,
						val:1
					})
				}
			}
		}
	}
</script>

<style lang="scss">
.goods-item{
			display: flex;
			padding: 10px 5px;
			border-bottom: 1px solid #f0f0f0;
			.item-left{
				display: flex;
				align-items: center;
				height: 100px;
				image{
					width: 100px;
					height: 100px;
				}
			}
			.item-right {
					width: 100%;
			    display: flex;
			    flex-direction: column;
			    justify-content: space-between;
					padding: 5px;
					box-sizing: border-box;
			    .title{
			      font-size: 13px;
			    }
			    .price {
			      font-size: 16px;
			      color: #c00000;
						display: flex;
						justify-content: space-between;
			    }
			  }
		}
</style>